package com.szmengran.dto;

import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Response with batch record to return,
 * usually use in conditional query
 * @author Joe
 * @date 2021/10/12 14:48
 * @version 1.0
 */
@Setter
public class MultiResponse<T> extends Response implements Serializable {

    private static final long serialVersionUID = 1L;

    private Collection<T> data;

    public List<T> getData() {
        return null == data ? Collections.emptyList() : new ArrayList<>(data);
    }

    public MultiResponse(Collection<T> data) {
        super();
        this.data = data;
    }

    public static <T> MultiResponse<T> success(Collection<T> data) {
        return new MultiResponse<T>(data);
    }

}
